﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;

namespace DAO
{
    public class LoiMatHangDAO
    {
        public List<LoiMatHangDTO> LayDSLMH()
        {
            SqlConnection conn = DataProvider.ConnectDB();
            string sql = "SELECT MaLoiMatHang, TenLoiMatHang FROM LOIMATHANG";
            SqlCommand cmd = new SqlCommand(sql, conn);

            SqlDataReader reader = cmd.ExecuteReader();
            List<LoiMatHangDTO> ds = new List<LoiMatHangDTO>();

            while (reader.Read())
            {
                LoiMatHangDTO lmhDTO = new LoiMatHangDTO();

                lmhDTO.MaLoiMH = reader.GetInt32(0);
                lmhDTO.TenLoiMH = reader.GetString(1);


                ds.Add(lmhDTO);
            }

            conn.Close();
            return ds;

        }
        public int LayMaLoiMH(string ten)
        {
            int ma = 0;
            string sql = "Select MaLoiMatHang From LOIMATHANG Where TenLoiMatHang= " + "N'" + ten + "'";

            SqlConnection conn = DataProvider.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                ma = reader.GetInt32(0);
            }
            conn.Close();
            return ma;
        }
    }
}

